#!/bin/bash
#
# Program name: user.sh
#
# -----------------------------
#
#   Show the login and names of
#   the system users
#
#   Obs.: read the data of the
#     file /etc/passwd
#
# -----------------------------
# 
# Versions:
#
# v1.0: show the users and the names
#   separeted by TAB
# v2.0: add suport to the -h option
# v3.0: add suport to the -V option
# v4.0: add the sort option
# v5.0: add the shift state

# FLAGS
order=0   # the output need to be ordered?

HELP_MESSAGE="
  Usage: $(basename "$0") [-h]

  Options:
    -h    Show the help screen
    -V    Show the software version
"

# computing of the options of the command line inputs
case "$1" in
  -h, --help)
    echo "$HELP_MESSAGE"
    exit 0
  ;;

  -V, --version)
    echo "$0" version 3.0
    exit 0
  ;;

  -s, --sort)
    order=1
  ;;

  *)
    if test -n "$1"
    then
      echo Invalid option "$0"
      exit 1
    fi
  ;;
esac

# extract the list:
list=$(cut -d : -f 1,5 /ect/passwd)

# order the list (if it's necessary)
if test "$order" = 1
then
  list=$(echo "$list" | sort)
fi

# output
echo "$list" | tr : \\t
